package org.uni_hi.lsep.gui;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

public class StatusPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4077454089814320208L;

	private JLabel _statusLabel=null;
	
	private Timer _timer=null;
	
	
	public StatusPanel(){
		init();
	}
	
	protected void init(){
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		setName("statusPanel");
		
		add(getStatusLabel(), null);
	}
	
	private Timer getTimer(){
		if(_timer==null){
			_timer=new Timer(2000,new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					clearStatus();
				}
			});
			_timer.setRepeats(false);
		}
		return _timer;
	}
	
	protected void clearStatus() {
		getStatusLabel().setText(" ");
	}

	private JLabel getStatusLabel(){
		if(_statusLabel==null){
			_statusLabel = new JLabel();
			_statusLabel.setText("StatusBar");
			_statusLabel.setSize(640, 40);
			_statusLabel.setFont(new Font("",Font.PLAIN,12));
		}
		return _statusLabel;
	}
	
	public void setStatus(String status){
		getStatusLabel().setText(status);
		getTimer().start();
	}
	
}
